package com.dg11185.nearshop.view.adapter;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.nearshop.R;
import com.dg11185.libs.imageloader.core.ImageLoader;

/**
 * 会员日商家列表适配器
 * 
 * @author LWL_Private
 * @date 2014-5-11
 */
public class V_ShopListAdapter extends F_ShopListAdapter {

    private LayoutInflater mInflater;

    public V_ShopListAdapter(Context context, List<Map<String, Object>> data) {
        super(context, data);
        mInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    public static class ViewHolder {
        public ImageView cover;// 图片
        public TextView name;// 商家名称
        public TextView disContent;// 具体优惠内容
        public TextView discount;// 简短优惠描述
        public String merchantId;// 商家ID
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder vHolder = null;
        Map<String, Object> map = mData.get(position);
        if (convertView == null) {
            convertView = mInflater
                    .inflate(R.layout.view_vshop_list_item, null);
            vHolder = new ViewHolder();
            vHolder.cover = (ImageView) convertView
                    .findViewById(R.id.image_v_shop_cover);
            vHolder.name = (TextView) convertView
                    .findViewById(R.id.txt_v_shop_name);
            vHolder.disContent = (TextView) convertView
                    .findViewById(R.id.txt_v_dis_content);
            vHolder.discount = (TextView) convertView
                    .findViewById(R.id.txt_v_discount);
//            vHolder.merchantId = (String) map.get("merchantId");
            convertView.setTag(vHolder);
        }
        vHolder = (ViewHolder) convertView.getTag();
        vHolder.merchantId = (String) map.get("merchantId");
        Object obj1 = map.get("coverUrl");
        if (obj1 != null && obj1 instanceof String)
            ImageLoader.getInstance().displayImage((String) obj1,
                    vHolder.cover, options);

        Object obj2 = map.get("name");
        if (obj2 != null && obj2 instanceof String)
            vHolder.name.setText((String) obj2);

        Object obj3 = map.get("discount");
        if (obj3 != null && obj3 instanceof String)
            vHolder.discount.setText((String) obj3);

        Object obj4 = map.get("disContent");
        if (obj4 != null && obj4 instanceof String)
            vHolder.disContent.setText((String) obj4);


        return convertView;
    }

}
